package com.cgnpc.scp.hr.controller;

import cn.com.cgnpc.aep.bizcenter.appcenter.sdk.result.ApiResult;
import com.cgnpc.cud.annotation.OperatorType;
import com.cgnpc.cud.annotation.UBA;
import com.cgnpc.cud.core.domain.AjaxResult;
import com.cgnpc.scp.achievement.pojo.IdReq;
import com.cgnpc.scp.common.utils.AjaxResultUtil;
import com.cgnpc.scp.hr.mybatis.entity.HrDeployPlan;
import com.cgnpc.scp.hr.service.HrDeployPlanService;
import com.cgnpc.scp.sri.budget.mybatis.entity.BudgetInfo;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**********************************
 * 用途说明: 调试人资管理 - 人员调配
 * 作者姓名: zhangyibing
 * 创建时间: 2020年11月11日14:42:31
 ***********************************/
@RestController
@RequestMapping("/scp/hr/deployPlan")
public class HrDeployPlanController {
    private static final Logger LOGGER = LoggerFactory.getLogger(HrDeployPlanController.class);

    @Autowired
    private HrDeployPlanService hrDeployPlanService;

    @Autowired
    private MessageSource messageSource;
    /**********************************
     * 用途说明: 调试人资管理 - 人员调配(发起流程或存草稿)
     * 参数说明 params
     * 返回值说明:
     ***********************************/
    @ApiOperation(value="调试人资管理 - 人员调配")
//    @UBA(module = "人资管理", action = "人员调配", channel = OperatorType.Button)
    @PostMapping("/savePlan")
    public AjaxResult savePlan(HttpServletRequest request, @RequestBody Map<String, Object> params) {
        try {
            HrDeployPlan plan = hrDeployPlanService.savePlan(params);
            return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,plan);
        } catch (Exception e) {
            LOGGER.error("HrDeployPlanController listPage error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

    /**********************************
     * 用途说明: 提交/回退流程
     * 参数说明 params
     * 返回值说明:
     ***********************************/
    @PostMapping("/submitProcess")
//    @UBA(module = "人资管理", action = "人员调配流程提交/回退", channel = OperatorType.Button)
    @ApiOperation(value="提交/回退流程")
    public AjaxResult submitProcess(HttpServletRequest request,@RequestBody Map<String, Object> params) {
        try {
            ApiResult apiResult = hrDeployPlanService.submitProcess(params);
            return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,apiResult);
        } catch (Exception e) {
            LOGGER.error("HrDeployPlanController submitProcess error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

    /**********************************
     * 用途说明: 查看调配计划详情
     * 参数说明 params
     * 返回值说明:
     ***********************************/
    @PostMapping("/getDeployPlanInfo")
//    @UBA(module = "人资管理", action = "人员调配流程提交/回退", channel = OperatorType.Button)
    @ApiOperation(value="查看调配计划详情")
    public AjaxResult getDeployPlanInfo(HttpServletRequest request,@RequestBody IdReq idReq) {
        try {
            HrDeployPlan plan = hrDeployPlanService.getDeployPlanInfo(idReq.getId());
            return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,plan);
        } catch (Exception e) {
            LOGGER.error("HrDeployPlanController submitProcess error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

    /**********************************
     * 用途说明: 人资调配流程删除草稿
     * 参数说明 params
     * 返回值说明:
     ***********************************/
    @PostMapping("/deleteDraft")
    @ApiOperation(value="人资调配流程删除草稿")
    public AjaxResult deleteDraft(HttpServletRequest request,@RequestBody Map<String, Object> params) {
        try {
            ApiResult result = hrDeployPlanService.deleteDraft(params);
            return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,result);
        } catch (Exception e) {
            LOGGER.error("paperController submitProcess error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

}
